﻿@{
    ViewBag.Title = "AdManage";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
@model AdModel
<ul class="breadcrumb" style="margin-bottom: 7px;">
    <li><a href="#">首页</a> <span class="divider">/</span></li>
    <li><a href="#">内容管理</a> <span class="divider">/</span></li>
    <li class="active">广告管理</li>
</ul>
<form id="searchForm">
    <table style="width: 100%; margin-bottom: 5px;">
        <tr>
            <td style="width: 60px;">广告ID：</td>
            <td style="width: 160px;">@Html.TextBoxFor(x => x.Searcher.AdID)</td>
            <td style="width: 70px;">广告名称：</td>
            <td style="width: 160px;">@Html.TextBoxFor(x => x.Searcher.AdName)</td>
            <td style="text-align: left">
                <button class="button button-small" id="btnSearch" type="submit">搜索</button>
            </td>
            <td style="text-align: right">
                <button class="button button-small button-primary" id="btnCreate" type="button">新建</button>
            </td>
        </tr>
    </table>
</form>
<div id="grid">
</div>
<script type="text/javascript">
    var Grid = BUI.Grid,
    Store = BUI.Data.Store,
    columns = [
      { title: '广告ID', width: 200, sortable: false, dataIndex: 'ID' },
      { title: '广告名称', width: 200, sortable: false, dataIndex: 'RoleDesc' },
      { title: '类型', width: 100, sortable: false, dataIndex: 'RoleType' },
      { title: '启用', width: 100, sortable: false, dataIndex: 'RoleType' },
      {
          title: '操作', width: 110, sortable: false, dataIndex: 'ID',
          renderer: function (value, obj) {
              return '<span class="grid-command" onclick="Edit(\'' + value + '\')">编辑</span><span class="grid-command" onclick="Delete(\'' + value + '\')" >删除</span>';
          }
      }
    ];
    //加载列表
    var store = new Store({
        url: '/Admin/System/AjaxGetAdList',
        proxy: {
            limitParam: 'pageSize',
            method: 'post'
        },
        autoLoad: true,
        pageSize: 10
    }),
    grid = new Grid.Grid({
        render: '#grid',
        loadMask: true,
        forceFit: true,
        plugins: [Grid.Plugins.AutoFit],
        columns: columns,
        store: store,
        bbar: {
            pagingBar: true
        }
    });
    grid.render();

    var Overlay = BUI.Overlay
    var dialog = null;
    //新建页面
    $('#btnCreate').click(function () {
        dialog = new Overlay.Dialog({
            title: '广告管理->新建广告',
            width: 730,
            closeAction: 'destroy',
            height: 510,
            buttons: [],
            bodyStyle: { 'padding': '0px' },
            bodyContent: '<iframe frameborder="0" style="width:720px;height:448px" src="/Admin/System/AddAd"></iframe>'
        });
        dialog.show();
    })
    function Edit(id) {
        dialog = new Overlay.Dialog({
            title: '广告管理->编辑广告',
            width: 730,
            closeAction: 'destroy',
            height: 510,
            buttons: [],
            bodyStyle: { 'padding': '0px' },
            bodyContent: '<iframe frameborder="0" style="width:720px;height:448px" src="/Admin/System/EditAd/' + id + '"></iframe>'
        });
        dialog.show();
    }

    function Delete(id) {
        if (confirm('确定删除？')) {
            $.ajax({
                type: 'post',
                url: '/Admin/System/DeleteAd/' + id,
                success: function (res) {
                    $('#btnSearch').trigger('click');
                }
            })
        }
    }
    //搜索
    var form = $('#searchForm')[0];
    $(form).on('submit', function (ev) {
        ev.preventDefault();
        var obj = BUI.FormHelper.serializeToObject(form);
        obj.pageIndex = 0;
        obj.start = 0;
        store.load(obj);
    });

    function SubmitSuccess() {
        dialog.close();
        $('#btnSearch').trigger('click');
    }
    function CloseWin() {
        dialog.close();
    }
</script>


